package com.redis.filter;

import com.redis.filter.redission.BloomFilterService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.*;

@SpringBootApplication
public class Application {
	private static final String key = "bloom_test";

	public static void main(String[] args) {
		ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);

		RedisTemplate redisTemplate = (RedisTemplate) context.getBean("redisTemplate");
		redisTemplate.delete(key);

		System.out.println("------test--start--------");
//		RedisService redisService = context.getBean(RedisService.class);

		BloomFilterService bloomFilterService = context.getBean(BloomFilterService.class);

		System.out.println("------add--start--------");

		Set<String> set = new HashSet<String>(1000);
		List<String> list = new ArrayList<String>(1000);
		for (int i = 0; i < 10000; i++) {
			String uuid = UUID.randomUUID().toString();
			if(i<1000){
				set.add(uuid);
				list.add(uuid);
			}
//			redisService.addByBloomFilter(key, uuid);
			bloomFilterService.add(key, uuid);
		}

		for (int i = 0; i < 10; i++) {
			String uuid = UUID.randomUUID().toString();
			list.add(uuid);
		}

		System.out.println("------search--start--------");

		for (String k: list){
			System.out.println("-------------" + k + "--------------");
//			System.out.println(redisService.includeByBloomFilter(key, k));
			System.out.println(bloomFilterService.contains(key, k));
			System.out.println("-------------" + k + "--------------");
		}

	}
}
